layui.use(['table', 'jquery', 'element', 'form'], function () {
    var table = layui.table;
    var $ = layui.$;
    var element = layui.element;
    var form = layui.form;

    table.render({
        elem: '#table'
        , url: '/emp/getTransfer'
        , where: {
            search: 0
        }
        , id: "transfer-table"
        , page: true
        , height: 512
        , limit: 10
        , cols: [[
            // {field: 'emp', title: '员工编号'}
            {field: 'empName', title: '员工', width: 98}
            , {field: 'time', title: '调动时间', width: 165}
            , {field: 'dNameBefore', title: '前部门', width: 98}
            , {field: 'dName', title: '现部门', width: 98}
            // ,{field:'area',title:'区域'}
            // ,{field:'nativePlace',title:'籍贯'}
            // ,{field:'state',title:'状态'}
            , {field: 'stateBefore', title: '前状态', width: 75}
            , {field: 'state', title: '现状态', width: 75}
            , {field: 'levelBefore', title: '前职务', width: 90}
            , {field: 'level', title: '现职务', width: 90}
            , {field: 'admin', title: '调为管理员', width: 100}
            // , {field: 'operation', title: '操作', fixed: 'right', width: 110, align: 'center', toolbar: '#barDemo'}
        ]]
    });


    element.on('tab(tab)', function (data) {
        var index = data.index;
        console.log(index);
        if (index == 0) {
            location.href = '/emp';
        } else if (index == 1) {
            location.href = '/emp/department';
        } else if (index == 2) {
            location.href = '/emp/entry';
        }
        return false;
    });

    var newTransfer = $('#newTransfer');
    var transferForm = $('#newTransferForm');

    transferForm.hide();

    newTransfer.click(function () {

        layer.open({
            title: "新增调动",
            type: 1,
            area: 'auto',
            maxWidth: 1000,
            content: $("#newTransferForm")
        });
        transferForm.show();
        return false;
    });

    form.on('submit(newTransferSubmit)', function (data) {
        $.post('/emp/newTransfer', data.field, function (data) {
            if (!data.status) {
                layer.open({title: '警告', content: data.msg});
            } else {
                transferForm[0].reset();
                layer.closeAll();
                layer.open({
                    title: '成功',
                    content: "员工调动成功！"
                });
                table.reload('transfer-table')
            }
        });
        return false;
    });

    form.on('submit(search)', function (data) {
        table.reload('transfer-table', {
            where: {
                search: data.field.id
            }
        });

        return false;
    });


});